﻿#region Copyright

// /*
// SilverlightInEnterprise
// SilverlightInEnterprise.UnitTesting.TargetApplication
// SearchPersonScreenViewModel.cs
// 
// Author: Matt Van Horn
// Created 11/16/2011 3:28 PM
// Copyright: Silverlight in the Enterprise www.slinenterprise.com
// 
// Licensed under MS-PL http://www.opensource.org/licenses/MS-PL and while you 
// may use this in anyway you see fit and owe us nothing to do so, we wouldn't mind knowing that you got value out of the work we did (so we will do more) so 
// we ask that you leave a comment on www.slinenterprise.com or on the codeplex site slinenterprise.codeplex.com
// 
// */

#endregion

using System.Windows.Input;
using SilverlightInEnterprise.Core.ViewModels;

namespace SilverlightInEnterprise.UnitTesting.TargetApplication.ViewModels
{
    public class SearchPersonScreenViewModel : ScreenViewModelBase
    {
        #region LastName Property

        private string _LastName;

        public string LastName
        {
            get { return this._LastName; }
            set
            {
                if (this._LastName != value)
                {
                    this._LastName = value;
                    this.OnPropertyChanged("LastName");
                    this.searchCommand.ChangeCanExecute();
                }
            }
        }

        #endregion

        #region FirstName Property

        private string _FirstName;

        public string FirstName
        {
            get { return this._FirstName; }
            set
            {
                if (this._FirstName != value)
                {
                    this._FirstName = value;
                    this.OnPropertyChanged("FirstName");
                    this.searchCommand.ChangeCanExecute();
                }
            }
        }

        #endregion

        #region SSN Property

        private string _SSN;

        public string SSN
        {
            get { return this._SSN; }
            set
            {
                if (this._SSN != value)
                {
                    this._SSN = value;
                    this.OnPropertyChanged("SSN");
                    this.searchCommand.ChangeCanExecute();
                }
            }
        }

        #endregion

        private GenericCommand searchCommand;

        public ICommand SearchCommand
        {
            get { return this.searchCommand; }
        }

        private void Search(object parameter)
        {
        }

        private bool CanSearch(object parameter)
        {
            bool allowedToSearch = true;
            if (!string.IsNullOrEmpty(this.SSN))
            {
                allowedToSearch = this.SSN.Length == 9;
            }
            else
            {
                if (string.IsNullOrEmpty(this.LastName))
                {
                    allowedToSearch = false;
                }
                else
                {
                    allowedToSearch = this.LastName.Length > 2;
                }
            }
            return allowedToSearch;
        }


        public SearchPersonScreenViewModel()
        {
            this.searchCommand = new GenericCommand(Search, CanSearch);
            this.Title = "Search Person";
        }
    }
}